package com.lyz.dataStructure.algorithm.快手2020;

import java.util.Scanner;

/*
合并两个内容流，实现隔4个插一个，如果合并完还有剩余，则加内容流尾部

input
1 2 3 4 5 6 7 8 9
a b c

output
1 2 3 4 a 5 6 7 8 b 9 c
 */
public class 合并内容流 {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String s1=sc.nextLine();
        String s2=sc.nextLine();
        System.out.println(outPutStream(s1,s2));
    }

    public static String outPutStream(String s1,String s2){
        StringBuffer st1 = new StringBuffer();
        StringBuffer st2 = new StringBuffer();
        StringBuffer st3 = new StringBuffer();
        for(int i =0;i<s1.length();i++){
            if(s1.charAt(i)!=' '){
                st1.append(s1.charAt(i));
            }
        }
        for(int i =0;i<s2.length();i++){
            if(s2.charAt(i)!=' '){
                st2.append(s2.charAt(i));
            }
        }
        int one =0;
        int two =0;
        int count =0;
        while (one<st1.length()&&two<st2.length()){
            if(count!=4){
                st3.append(st1.charAt(one));
                one++;
                count++;
            }else {
                st3.append(st2.charAt(two));
                two++;
                count = 0;
            }
        }
        if(two!=st2.length()){
            for(;two<st2.length();two++){
                st3.append(st2.charAt(two));
            }
        }
        StringBuffer st4 = new StringBuffer();
        for(int i=0;i<st3.length();i++){
            st4.append(st3.charAt(i));
            st4.append(' ');
        }
        return st4.toString().trim();

    }

   /* public static void streamOutput(String s1,String s2){
        StringBuilder str=new StringBuilder();
        int l=0;
        int r=0;
        int count=0;
        while(l<s1.length()&&r<s2.length()){
            if(s1.charAt(l)==' '){
                l++;
                continue;
            }
            if(s2.charAt(r) == ' ') {
                r++;
                continue;
            }
            if(count!=4){
                str.append(s1.charAt(l));
                l++;
                count++;
            }else if(count==4){
                str.append(s2.charAt(r));
                r++;
                count=0;
            }
        }
        if(l!=s1.length()){
            for(;l<s1.length();l++){
                if(s1.charAt(l)!=' '){
                    str.append(s1.charAt(l));
                }
            }
        }
        if(r!=s2.length()){
            for(;r<s2.length();r++){
                if(s2.charAt(r)!=' '){
                    str.append(s2.charAt(r));
                }
            }
        }
        String right=str.toString();
        StringBuilder res=new StringBuilder();
        for(int i=0;i<right.length();i++){
            if(i!=right.length()-1){
                System.out.print(right.charAt(i));
                System.out.print(" ");
            }
            else{
                System.out.print(right.charAt(i));
            }
        }*/

}
